package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * The type Dish controller.
 */
@RestController
@Slf4j
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理")
@RequiredArgsConstructor
public class DishController {
    private final DishService dishService;


    /**
     * 新增菜品
     *
     * @param dishDTO the dish dto
     * @return the result
     */
    @ApiOperation("新增菜品")
    @PostMapping
    public Result<?> create(@RequestBody DishDTO dishDTO) {
        dishService.create(dishDTO);
        return Result.success();
    }

    /**
     * 菜品分页查询
     *
     * @param dishPageQueryDTO the dish page query dto
     * @return the result
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        log.info("菜品分页查询:{}", dishPageQueryDTO);
        PageResult pageResult = dishService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除菜品
     *
     * @param ids the ids
     * @return the result
     */
    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result<?> deleteBatch(@RequestParam List<Long> ids) {
        dishService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 菜品查询回显
     *
     * @param id the id
     * @return the result
     */
    @GetMapping("/{id}")
    @ApiOperation("菜品查询回显")
    public Result<DishVO> infoById(@PathVariable Long id) {
        DishVO dishVO = dishService.infoById(id);
        return Result.success(dishVO);
    }
    @ApiOperation("修改菜品")
    @PutMapping
    public Result<?> update(@RequestBody DishDTO dishDTO) {
        dishService.update(dishDTO);
        return Result.success();
    }
}
